package com.code;

import java.io.IOException;
import java.util.ArrayList;

import com.database.DBCallHistory;
import com.example.R;
import com.object.obKeyValue;
import com.service.GoogleSearch;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Service_ShowCusDetail extends Activity {
	public static ListView lvValueSearch;
	private ArrayList<String> valueSearch;
	private String phoneNumber = "";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.callhistory);

//		lvValueSearch = (ListView) findViewById(R.id.lvValueSearch);
		// editTextInput = (Ed itText) findViewById(R.id.editTextInput);
		phoneNumber = super.getIntent().getExtras().getString("phone");
		valueSearch = new ArrayList<String>();
		 valueSearch = super.getIntent().getExtras().getStringArrayList("detailPhoneCall");
		 DBCallHistory dbCalHis = new DBCallHistory(this);
		 dbCalHis.open();
		int id = dbCalHis.InsertCallHistory(phoneNumber);
		for (int i = 0; i < valueSearch.size(); i++) {
			dbCalHis.InsertCallHistoryDetail(String
					.valueOf(id), valueSearch.get(i)
					.toString());
		}
		dbCalHis.close();
//		try {
//			valueSearch = GoogleSearch.getValueToGoogleSearchs(phoneNumber);
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		ArrayList<String> contentSearch = new ArrayList<String>();
//		if (valueSearch != null && valueSearch.size() > 0) {
//			for (obKeyValue ob : valueSearch) {
//				contentSearch.add((String) ob.getKey());
//			}
//			ArrayAdapter<String> arrAp = new ArrayAdapter<String>(this,
//					android.R.layout.simple_list_item_1, contentSearch);
//			lvValueSearch.setAdapter(arrAp);
//		} else {
//			String tmp = phoneNumber.substring(0, 2).toString();
//			String tmpNumber = phoneNumber.substring(2, phoneNumber.length())
//					.toString();
//			if (!tmp.equals("01") && !tmp.equals("09")) {
//				String tNewPhone = "("+tmp+")" + tmpNumber;
//				try {
//					valueSearch = GoogleSearch
//							.getValueToGoogleSearchs(tNewPhone);
//				} catch (IOException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//				ArrayList<String> contentSearchs = new ArrayList<String>();
//				if (valueSearch != null && valueSearch.size() > 0) {
//					for (obKeyValue ob : valueSearch) {
//						contentSearchs.add((String) ob.getKey());
//					}
//					ArrayAdapter<String> arrAp = new ArrayAdapter<String>(this,
//							android.R.layout.simple_list_item_1, contentSearchs);
//					lvValueSearch.setAdapter(arrAp);
//				}
//			}
//		}
		// lvValueSearch.setOnClickListener(new OnClickListener() {
		// public void onClick(View v) {
		//
		// }
		// });
	}

}
